﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
using System.Xml;

//http://www.fmylife.com/
namespace CSharpBot
{
    //This can be accessed from anywhere within this project.
    public static class Parse
    {
        private static bool sandbox = true;
        private static readonly string apiKey = "apikeyforsandbox";
        private static string lang = "en";

        public static string[] buildInFMLs = {
        "Today, my iPhone got back from being fixed. When I opened the box there was a note attached to my phone that said, 'All you had to do was turn it on.' FML"
                                             };
 
        public static void parseXML(int FMLNum)
        {
            if (sandbox == true)
            {
                String xmlString = new WebClient().DownloadString("http://sandbox.betacie.com/?key=" + apiKey + "&language=" + lang);
                using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
                {
                    reader.ReadToFollowing("error");
                    reader.MoveToFirstAttribute();
                    string error = reader.Value;
                    try { int _errorID = Convert.ToInt32(error); Console.WriteLine(catchError(_errorID)); } catch { }
                }
            }
        }

        public static string catchError(int errorID)
        {
            string errorMessage = "";

            //API Errors
            if (errorID == 1001)
                errorMessage = "[1001] Impossible action in read-only mode.";
            else if (errorID == 1002)
                errorMessage = "[1002] Invalid API key.";
            else if (errorID == 1003)
                errorMessage = "[1003] Too many requests - aborting.";
            else if (errorID == 1004)
                errorMessage = "[1004] No corresponding parameter.";
            else if (errorID == 1005)
                errorMessage = "[1005] Comments closed.";
            //User Errors
            else if (errorID == 2001)
                errorMessage = "[2001] Invalid or inexistent token.";
            else if (errorID == 2002)
                errorMessage = "[2002] Already voted.";
            else if (errorID == 2003)
                errorMessage = "[2003] Banned member.";
            else if (errorID == 2004)
                errorMessage = "[2004] Account is unverified.";
            else if (errorID == 2005)
                errorMessage = "[2005] Bad login information.";
            else if (errorID == 2006)
                errorMessage = "[2006] This user name or email address is already in use on the website.";
            else if (errorID == 2007)
                errorMessage = "[2007] Anti-flood protection.";
            else if (errorID == 2008)
                errorMessage = "[2008] Banned IP address.";
            else if (errorID == 2009)
                errorMessage = "[2009] Out of time limit.";
            else if (errorID == 2010)
                errorMessage = "[2010] Specified member doesn't exist.";
            //Variable Errors
            else if (errorID == 3001)
                errorMessage = "[3001] Variable is missing.";
            else if (errorID == 3002)
                errorMessage = "[3002] Bad article number.";
            else if (errorID == 3003)
                errorMessage = "[3003] Article length must be greater than 30 characters.";
            else if (errorID == 3004)
                errorMessage = "[3004] URL are fobidden in an article.";
            else if (errorID == 3005)
                errorMessage = "[3005] E-mails are forbidden in an article.";
            else if (errorID == 3006)
                errorMessage = "[3006] Your login contains invalid characters.";
            else if (errorID == 3007)
                errorMessage = "[3007] You must enter a valid email address.";
            else if (errorID == 3008)
                errorMessage = "[3008] Filesize exceeded.";
            else if (errorID == 3009)
                errorMessage = "[3009] Invalid filetype.";
            else if (errorID == 3010)
                errorMessage = "[3010] Invalid submitted data.";

            return errorMessage;
        }
    }
}
